/**
 * @file    app_massage.c
 * @author  yhy
 * @brief   按摩系统源文件，基于电磁阀系统实现不同按摩模式
 * @version 1.01
 * @date    2025-07-24
 *
 * @copyright Copyright (c) 2025
 *
 * @details
 * Change Logs:
 * Date           Author       Notes
 * 2025-07-30     yhy          the first version V1.00
 * 2025-10-22     yhy          新增按摩手动控制模块，实现单独控制每个气袋 V1.01
 *
 */
#include "app_massage.h"

#include "app_control.h"
#include "app_storage.h"
#include "common_debug.h"
#include "inf_pump.h"

#include <string.h>

#define MASSAGE_POWER_DOWN_REMEMBER_TIME_MS (30 * 1000U)

static result_e app_massage_validate_mode(massage_mode_e mode);
static result_e app_massage_validate_intensity(massage_intensity_e intensity);
static void     app_massage_process_running_state(void);
static void     app_massage_process_switching_state(void);
static void     app_massage_enable_current_group(void);
static void     app_massage_disable_current_group(void);
static void     app_massage_switch_to_next_group(void);
static void     app_massage_apply_pending_changes(void);
static uint32_t app_massage_get_inflate_time_by_intensity(massage_intensity_e intensity);
static void     app_massage_power_down_remember(void);

/* 按摩系统实例 */
massage_system_t massage_system;

/* 波浪模式电磁阀组配置 */
static massage_valve_group_t wave_mode_groups[] = {
    { { MASSAGE_VALVE_IDX_1, MASSAGE_VALVE_IDX_2 }, 2 },
    { { MASSAGE_VALVE_IDX_3, MASSAGE_VALVE_IDX_4 }, 2 },
    { { MASSAGE_VALVE_IDX_5, MASSAGE_VALVE_IDX_6 }, 2 },
    { { MASSAGE_VALVE_IDX_7, MASSAGE_VALVE_IDX_8 }, 2 },
    { { MASSAGE_VALVE_IDX_9, MASSAGE_VALVE_IDX_10 }, 2 },
    { { MASSAGE_VALVE_IDX_11, MASSAGE_VALVE_IDX_12 }, 2 },
};

/* 脉冲模式电磁阀组配置 */
static massage_valve_group_t pulse_mode_groups[] = {
    { { MASSAGE_VALVE_IDX_1 }, 1 },  { { MASSAGE_VALVE_IDX_2 }, 1 },  { { MASSAGE_VALVE_IDX_3 }, 1 },
    { { MASSAGE_VALVE_IDX_4 }, 1 },  { { MASSAGE_VALVE_IDX_5 }, 1 },  { { MASSAGE_VALVE_IDX_6 }, 1 },
    { { MASSAGE_VALVE_IDX_7 }, 1 },  { { MASSAGE_VALVE_IDX_8 }, 1 },  { { MASSAGE_VALVE_IDX_9 }, 1 },
    { { MASSAGE_VALVE_IDX_10 }, 1 }, { { MASSAGE_VALVE_IDX_11 }, 1 }, { { MASSAGE_VALVE_IDX_12 }, 1 },
};

/* 手动模式电磁阀组配置（单个气袋控制） */
static massage_valve_group_t manual_mode_groups[] = {
    { { MASSAGE_VALVE_IDX_1 }, 1 },  { { MASSAGE_VALVE_IDX_2 }, 1 },  { { MASSAGE_VALVE_IDX_3 }, 1 },
    { { MASSAGE_VALVE_IDX_4 }, 1 },  { { MASSAGE_VALVE_IDX_5 }, 1 },  { { MASSAGE_VALVE_IDX_6 }, 1 },
    { { MASSAGE_VALVE_IDX_7 }, 1 },  { { MASSAGE_VALVE_IDX_8 }, 1 },  { { MASSAGE_VALVE_IDX_9 }, 1 },
    { { MASSAGE_VALVE_IDX_10 }, 1 }, { { MASSAGE_VALVE_IDX_11 }, 1 }, { { MASSAGE_VALVE_IDX_12 }, 1 },
};

/* 按摩模式配置表 */
static massage_mode_config_t massage_mode_configs[MASSAGE_MODE_MAX] = {
    [MASSAGE_MODE_WAVE]   = { wave_mode_groups, sizeof(wave_mode_groups) / sizeof(wave_mode_groups[0]),
                              15 }, // 默认15分钟
    [MASSAGE_MODE_PULSE]  = { pulse_mode_groups, sizeof(pulse_mode_groups) / sizeof(pulse_mode_groups[0]),
                              15 }, // 默认15分钟
    [MASSAGE_MODE_MANUAL] = { manual_mode_groups,
                              sizeof(manual_mode_groups) / sizeof(manual_mode_groups[0]),
                              15 }, // 默认15分钟
};

/* 强度对应的充气时间（毫秒） */
static const uint32_t intensity_inflate_times[MASSAGE_INTENSITY_MAX] = {
    [MASSAGE_INTENSITY_LOW]    = 2000, // 2秒
    [MASSAGE_INTENSITY_MEDIUM] = 4000, // 4秒
    [MASSAGE_INTENSITY_HIGH]   = 6000, // 6秒
};

/* 按摩电磁阀序号对照表 */
static const uint8_t valve_idx_map[] = {
    [MASSAGE_VALVE_IDX_1] = 0,  [MASSAGE_VALVE_IDX_2] = 1,   [MASSAGE_VALVE_IDX_3] = 2,
    [MASSAGE_VALVE_IDX_4] = 3,  [MASSAGE_VALVE_IDX_5] = 4,   [MASSAGE_VALVE_IDX_6] = 5,
    [MASSAGE_VALVE_IDX_7] = 6,  [MASSAGE_VALVE_IDX_8] = 7,   [MASSAGE_VALVE_IDX_9] = 8,
    [MASSAGE_VALVE_IDX_10] = 9, [MASSAGE_VALVE_IDX_11] = 10, [MASSAGE_VALVE_IDX_12] = 11,
};

#define DEFLATE_TIME_MS 600U // 泄气时间固定600ms

/**
 * @brief 初始化按摩系统
 *
 * @return result_e 初始化结果
 */
result_e app_massage_init(void)
{
    /* 初始化按摩系统参数 */
    massage_system.is_open                  = false;
    massage_system.is_remember              = false;
    massage_system.state                    = MASSAGE_STATE_STOPPED;
    massage_system.current_mode             = MASSAGE_MODE_WAVE;
    massage_system.current_intensity        = MASSAGE_INTENSITY_MEDIUM;
    massage_system.current_group_index      = 0U;
    massage_system.group_timer_ms           = 0U;
    massage_system.total_timer_ms           = 0U;
    massage_system.inflate_time_ms          = intensity_inflate_times[MASSAGE_INTENSITY_MEDIUM];
    massage_system.deflate_time_ms          = DEFLATE_TIME_MS;
    massage_system.mode_change_pending      = false;
    massage_system.intensity_change_pending = false;

    /* 初始化记忆相关字段 */
    massage_system.remember_data_saved  = false;
    massage_system.last_saved_mode      = MASSAGE_MODE_WAVE;
    massage_system.last_saved_intensity = MASSAGE_INTENSITY_MEDIUM;

    LOG("Massage system initialized successfully\n");
    return RESULT_STATUS_OK;
}

/**
 * @brief 控制单个按摩气袋
 *
 * @param valve_idx 气袋序号
 * @param mode      控制模式 (1:高强度启动, 2:中强度启动, 3:低强度启动, 4:停止)
 * @return result_e 操作结果
 */
result_e app_massage_ctrl_single_valve(massage_valve_idx_e valve_idx, massage_manual_mode_e mode)
{
    /* 参数验证 */
    if (valve_idx >= MASSAGE_VALVE_IDX_MAX) {
        LOG("Invalid valve index: %d", valve_idx);
        return RESULT_STATUS_INVALID_PARAM;
    }

    /* 检查按摩系统是否开启 */
    if (!massage_system.is_open) {
        LOG("Massage system is not open");
        return RESULT_STATUS_MASSAGE_NOT_OPEN;
    }

    /* 根据mode处理 */
    switch (mode) {
    case MASSAGE_MANUAL_MODE_START_HIGH:
    case MASSAGE_MANUAL_MODE_START_MID:
    case MASSAGE_MANUAL_MODE_START_LOW:
        /* 启动手动模式 */
        /* 先设置当前组索引为指定的气袋索引，这样只有这个气袋会循环充气放气 */
        massage_system.current_group_index = valve_idx_map[valve_idx];

        CHECK_RESULT(app_massage_start(MASSAGE_MODE_MANUAL, (massage_intensity_e)mode),
                     "Failed to start massage system in manual mode");

        LOG("Single valve control started: valve=%d, intensity=%d", valve_idx_map[valve_idx], mode);
        break;

    case MASSAGE_MANUAL_MODE_STOP:
        /* 停止整个按摩系统 */
        CHECK_RESULT(app_massage_stop(), "Failed to stop massage system");
        LOG("Single valve control stopped");
        break;

    default: LOG("Invalid manual mode: %d", mode); return RESULT_STATUS_INVALID_PARAM;
    }

    return RESULT_STATUS_OK;
}

/**
 * @brief 开始按摩
 *
 * @param mode      按摩模式
 * @param intensity 按摩强度
 * @return result_e 操作结果, 开启返回RESULT_STATUS_OK, 未开启返回其他
 */
result_e app_massage_start(massage_mode_e mode, massage_intensity_e intensity)
{
    /* 检查按摩系统是否已打开 */
    if (!massage_system.is_open) {
        return RESULT_STATUS_MASSAGE_NOT_OPEN;
    }

    /* 校验模式和强度 */
    CHECK_RESULT(app_massage_validate_mode(mode), "Validate mode failed");
    CHECK_RESULT(app_massage_validate_intensity(intensity), "Validate intensity failed");

    /* 如果正在运行，先停止 */
    if (massage_system.state != MASSAGE_STATE_STOPPED) {
        app_massage_stop();
    }

    /* 启用电磁阀系统 */
    CHECK_RESULT(inf_solenoid_valve_set_system_enable(true), "Failed to enable solenoid valve system");

    /* 设置按摩参数 */
    massage_system.current_mode             = mode;
    massage_system.current_intensity        = intensity;
    massage_system.group_timer_ms           = 0U;
    massage_system.total_timer_ms           = 0U;
    massage_system.inflate_time_ms          = app_massage_get_inflate_time_by_intensity(intensity);
    massage_system.state                    = MASSAGE_STATE_RUNNING;
    massage_system.mode_change_pending      = false;
    massage_system.intensity_change_pending = false;

    /* 只有在非手动模式下才重置 current_group_index，手动模式保持当前值 */
    if (mode != MASSAGE_MODE_MANUAL) {
        massage_system.current_group_index = 0U;
    }

    /* 气泵充气 */
    result_e result = inf_pump_air_inflation();
    if (result != RESULT_STATUS_OK) {
        /* 清理已启用的电磁阀系统 */
        inf_solenoid_valve_set_system_enable(false);
        return result;
    }

    /* 启用第一组电磁阀 */
    app_massage_enable_current_group();

    LOG("Massage started: mode=%u, intensity=%u\n", mode, intensity);
    return RESULT_STATUS_OK;
}

/**
 * @brief 停止按摩
 *
 * @return result_e 操作结果
 */
result_e app_massage_stop(void)
{
    /* 关闭所有电磁阀 */
    inf_solenoid_valve_set_all_valves(false);
    inf_solenoid_valve_set_system_enable(false);

    /* 重置系统状态 */
    massage_system.state                    = MASSAGE_STATE_STOPPED;
    massage_system.current_group_index      = 0U;
    massage_system.group_timer_ms           = 0U;
    massage_system.total_timer_ms           = 0U;
    massage_system.mode_change_pending      = false;
    massage_system.intensity_change_pending = false;

    LOG("Massage stopped\n");

    /* 关闭气泵 */
    return inf_pump_air_stop();
}

/**
 * @brief 设置按摩模式
 *
 * @param   mode        新的按摩模式
 * @return  result_e    操作结果
 */
result_e app_massage_set_mode(massage_mode_e mode)
{
    result_e result = app_massage_validate_mode(mode);
    if (result != RESULT_STATUS_OK) {
        return result;
    }

    if (massage_system.state == MASSAGE_STATE_STOPPED) {
        massage_system.current_mode        = mode;
        /* 重置记忆状态，因为模式已改变 */
        massage_system.remember_data_saved = false;
        return RESULT_STATUS_OK;
    }

    /* 如果正在运行，标记待切换 */
    massage_system.pending_mode        = mode;
    massage_system.mode_change_pending = true;

    /* 刷新记忆：重置记忆计时和保存状态 */
    massage_system.is_remember         = false;
    massage_system.remember_data_saved = false;

    LOG("Mode change pending: %u\n", mode);
    return RESULT_STATUS_OK;
}

/**
 * @brief 设置按摩强度
 *
 * @param  intensity 新的按摩强度
 * @return result_e 操作结果
 */
result_e app_massage_set_intensity(massage_intensity_e intensity)
{
    result_e result = app_massage_validate_intensity(intensity);
    if (result != RESULT_STATUS_OK) {
        return result;
    }

    if (massage_system.state == MASSAGE_STATE_STOPPED) {
        massage_system.current_intensity   = intensity;
        massage_system.inflate_time_ms     = app_massage_get_inflate_time_by_intensity(intensity);
        /* 重置记忆状态，因为强度已改变 */
        massage_system.remember_data_saved = false;
        return RESULT_STATUS_OK;
    }

    /* 如果正在运行，标记待切换 */
    massage_system.pending_intensity        = intensity;
    massage_system.intensity_change_pending = true;

    /* 重置记忆计时和保存状态 */
    massage_system.is_remember         = false;
    massage_system.remember_data_saved = false;

    LOG("Intensity change pending: %u\n", intensity);
    return RESULT_STATUS_OK;
}

/**
 * @brief 设置按摩最大时间
 *
 * @param   time        新的最大按摩时间
 * @return  result_e    修改结果, 成功返回RESULT_STATUS_OK, 失败返回RESULT_STATUS_ERROR
 */
result_e app_massage_set_max_time(massage_time_e time)
{
    if (time > MASSAGE_TIME_MAX) {
        return RESULT_STATUS_INVALID_PARAM;
    }

    for (uint8_t i = 0; i < MASSAGE_MODE_MAX; ++i) {
        massage_mode_config_t *massage_mode_config = &massage_mode_configs[i];
        switch (time) {
        case MASSAGE_TIME_1: massage_mode_config->max_time_minutes = 5; break;
        case MASSAGE_TIME_2: massage_mode_config->max_time_minutes = 10; break;
        case MASSAGE_TIME_3: massage_mode_config->max_time_minutes = 15; break;
        }
    }

    return RESULT_STATUS_OK;
}

/**
 * @brief 获取当前按摩最大时间
 *
 * @return massage_time_e 最大按摩时间枚举
 */
massage_time_e app_massage_get_time(void)
{
    uint8_t massage_time_minutes =
        massage_mode_configs[(uint32_t)massage_system.current_mode].max_time_minutes;
    massage_time_e massage_time = MASSAGE_TIME_2;

    switch (massage_time_minutes) {
    case 5:  massage_time = MASSAGE_TIME_1; break;
    case 10: massage_time = MASSAGE_TIME_2; break;
    case 15: massage_time = MASSAGE_TIME_3; break;
    }

    return massage_time;
}

/**
 * @brief 获取当前按摩开关状态
 *
 * @return massage_switch_state_e 开关状态
 */
massage_switch_state_e app_massage_get_switch(void)
{
    return massage_system.is_open ? MASSAGE_SWITCH_STATE_ON : MASSAGE_SWITCH_STATE_OFF;
}

/**
 * @brief 按摩系统处理函数，50ms调度一次
 */
void app_massage_handle(void)
{
    if (massage_system.state == MASSAGE_STATE_STOPPED) {
        return;
    }

    /* 检查总按摩时间是否超时 */
    massage_system.total_timer_ms += 50;
    const massage_mode_config_t *config = &massage_mode_configs[massage_system.current_mode];
    if (massage_system.total_timer_ms >= (config->max_time_minutes * 60 * 1000)) {
        app_massage_stop();
        LOG("Massage stopped due to timeout\n");
        return;
    }

    /* 当按摩时间达到 */
    if (massage_system.total_timer_ms >= MASSAGE_POWER_DOWN_REMEMBER_TIME_MS) {
        massage_system.is_remember = true;
    }

    /* 根据当前状态处理 */
    switch (massage_system.state) {
    case MASSAGE_STATE_RUNNING:   app_massage_process_running_state(); break;
    case MASSAGE_STATE_SWITCHING: app_massage_process_switching_state(); break;
    default:                      break;
    }

    /* 处理掉电记忆 */
    app_massage_power_down_remember();
}

/**
 * @brief 按摩开关, 不打开无法进行按摩
 *
 * @param is_open true: 打开, false: 关闭
 */
void app_massage_switch(bool is_open) { massage_system.is_open = is_open; }

/**
 * @brief 获取当前按摩模式
 *
 * @return massage_mode_e 当前模式
 */
massage_mode_e app_massage_get_current_mode(void) { return massage_system.current_mode; }

/**
 * @brief 获取当前按摩强度
 *
 * @return massage_intensity_e 当前强度
 */
massage_intensity_e app_massage_get_current_intensity(void) { return massage_system.current_intensity; }

/**
 * @brief 获取指定按摩电磁阀当前状态（手动模式下有效）
 *
 * @param   idx                     电磁阀索引
 * @return  massage_manual_mode_e   手动模式状态
 */
massage_manual_mode_e app_massage_get_valve_status(massage_valve_idx_e idx)
{
    if (massage_system.current_mode != MASSAGE_MODE_MANUAL) {
        return MASSAGE_MANUAL_MODE_INVALID;
    }

    /* 如果当前按摩组索引和指定索引匹配，那么代表当前这个电磁阀正在被控制 */
    if (massage_system.current_group_index == valve_idx_map[idx]) {
        return (massage_manual_mode_e)massage_system.current_intensity;
    }
    else {
        return MASSAGE_MANUAL_MODE_STOP;
    }
}

/**
 * @brief 获取剩余按摩时间
 *
 * @return uint32_t 剩余时间（秒）
 */
uint32_t app_massage_get_remaining_time_seconds(void)
{
    if (massage_system.state == MASSAGE_STATE_STOPPED) {
        return 0U;
    }

    const massage_mode_config_t *config      = &massage_mode_configs[massage_system.current_mode];
    uint32_t                     max_time_ms = config->max_time_minutes * 60 * 1000;

    if (massage_system.total_timer_ms >= max_time_ms) {
        return 0U;
    }

    return (max_time_ms - massage_system.total_timer_ms) / 1000;
}

/**
 * @brief 掉电记忆，存储当前模式和强度
 *
 */
static void app_massage_power_down_remember(void)
{
    if (!massage_system.is_remember) {
        return;
    }

    /* 检查数据是否已经保存过，且当前数据与上次保存的数据相同 */
    if (massage_system.remember_data_saved &&
        massage_system.current_mode == massage_system.last_saved_mode &&
        massage_system.current_intensity == massage_system.last_saved_intensity) {
        return; /* 数据未变化，无需重复写入Flash */
    }

    massage_remember_data_t remember_data = {
        .mode      = massage_system.current_mode,
        .intensity = massage_system.current_intensity,
    };
    uint8_t remember_data_size = sizeof(massage_remember_data_t);

    /* 转换为字节数组 */
    uint8_t data[remember_data_size];
    memcpy(data, &remember_data, remember_data_size);

    if (app_storage_write(STORAGE_IDX_MASSAGE_REMEMBER, data, remember_data_size) == RESULT_STATUS_OK) {
        /* 写入成功，更新保存状态 */
        massage_system.remember_data_saved  = true;
        massage_system.last_saved_mode      = massage_system.current_mode;
        massage_system.last_saved_intensity = massage_system.current_intensity;
        LOG("Massage remember data saved: mode=%u, intensity=%u\n", massage_system.current_mode,
            massage_system.current_intensity);
    }
    else {
        LOG("Failed to write massage remember data\n");
    }
}

/**
 * @brief 处理运行状态
 */
static void app_massage_process_running_state(void)
{
    massage_system.group_timer_ms += 50;

    /* 检查是否到达充气时间 */
    if (massage_system.group_timer_ms >= massage_system.inflate_time_ms) {
        /* 禁用当前组，进入泄气阶段 */
        app_massage_disable_current_group();
        massage_system.state          = MASSAGE_STATE_SWITCHING;
        massage_system.group_timer_ms = 0U;
    }
}

/**
 * @brief 处理切换状态（泄气阶段）
 */
static void app_massage_process_switching_state(void)
{
    massage_system.group_timer_ms += 50;

    /* 检查是否到达泄气时间 */
    if (massage_system.group_timer_ms >= massage_system.deflate_time_ms) {
        /* 应用待处理的更改 */
        app_massage_apply_pending_changes();

        /* 切换到下一组 */
        app_massage_switch_to_next_group();

        /* 启用新的当前组 */
        app_massage_enable_current_group();

        massage_system.state          = MASSAGE_STATE_RUNNING;
        massage_system.group_timer_ms = 0U;
    }
}

/**
 * @brief 启用当前电磁阀组
 */
static void app_massage_enable_current_group(void)
{
    const massage_mode_config_t *config = &massage_mode_configs[massage_system.current_mode];
    const massage_valve_group_t *group  = &config->valve_groups[massage_system.current_group_index];

    for (uint8_t i = 0; i < group->channel_count; ++i) {
        inf_solenoid_valve_set_enable((solenoid_valve_channel_e)group->channels[i], true);
    }

    LOG("Enabled group %u with %u valves\n", massage_system.current_group_index, group->channel_count);
}

/**
 * @brief 禁用当前电磁阀组
 */
static void app_massage_disable_current_group(void)
{
    const massage_mode_config_t *config = &massage_mode_configs[massage_system.current_mode];
    const massage_valve_group_t *group  = &config->valve_groups[massage_system.current_group_index];

    for (uint8_t i = 0; i < group->channel_count; ++i) {
        inf_solenoid_valve_set_enable((solenoid_valve_channel_e)group->channels[i], false);
    }

    LOG("Disabled group %u\n", massage_system.current_group_index);
}

/**
 * @brief 切换到下一组电磁阀
 */
static void app_massage_switch_to_next_group(void)
{
    const massage_mode_config_t *config = &massage_mode_configs[massage_system.current_mode];

    /* 在手动模式下，不切换组，保持在当前气囊上循环 */
    if (massage_system.current_mode == MASSAGE_MODE_MANUAL) {
        LOG("Manual mode: staying on group %u\n", massage_system.current_group_index);
        return;
    }

    ++massage_system.current_group_index;
    if (massage_system.current_group_index >= config->group_count) {
        massage_system.current_group_index = 0U; // 循环到第一组
    }

    LOG("Switched to group %u\n", massage_system.current_group_index);
}

/**
 * @brief 应用待处理的更改
 */
static void app_massage_apply_pending_changes(void)
{
    bool settings_changed = false;

    if (massage_system.mode_change_pending) {
        massage_system.current_mode        = massage_system.pending_mode;
        massage_system.current_group_index = 0U; // 重置到第一组
        massage_system.total_timer_ms      = 0U; // 重置总时间
        massage_system.mode_change_pending = false;
        settings_changed                   = true;
        LOG("Applied mode change to %u\n", massage_system.current_mode);
    }

    if (massage_system.intensity_change_pending) {
        massage_system.current_intensity = massage_system.pending_intensity;
        massage_system.inflate_time_ms =
            app_massage_get_inflate_time_by_intensity(massage_system.current_intensity);
        massage_system.intensity_change_pending = false;
        settings_changed                        = true;
        LOG("Applied intensity change to %u\n", massage_system.current_intensity);
    }

    /* 如果有设置变更，重置记忆状态和计时 */
    if (settings_changed) {
        massage_system.is_remember         = false;
        massage_system.remember_data_saved = false;
        massage_system.total_timer_ms      = 0U; // 重新开始30秒计时
        LOG("Settings changed, reset remember timer\n");
    }
}

/**
 * @brief 根据强度获取充气时间
 *
 * @param intensity 按摩强度
 * @return uint32_t 充气时间（毫秒）
 */
static uint32_t app_massage_get_inflate_time_by_intensity(massage_intensity_e intensity)
{
    if (intensity < MASSAGE_INTENSITY_MAX) {
        return intensity_inflate_times[intensity];
    }
    return intensity_inflate_times[MASSAGE_INTENSITY_MEDIUM]; // 默认中等强度
}

/**
 * @brief 验证按摩模式参数
 *
 * @param mode 按摩模式
 * @return result_e 验证结果
 */
static result_e app_massage_validate_mode(massage_mode_e mode)
{
    if (mode >= MASSAGE_MODE_MAX) {
        return RESULT_STATUS_INVALID_PARAM;
    }
    return RESULT_STATUS_OK;
}

/**
 * @brief 验证按摩强度参数
 *
 * @param intensity 按摩强度
 * @return result_e 验证结果
 */
static result_e app_massage_validate_intensity(massage_intensity_e intensity)
{
    if (intensity >= MASSAGE_INTENSITY_MAX) {
        return RESULT_STATUS_INVALID_PARAM;
    }
    return RESULT_STATUS_OK;
}
